package com.source.lightfowl.handler;
import com.source.lightfowl.utils.MyResult;

import com.source.lightfowl.utils.StatusCode;
import org.apache.tomcat.util.http.fileupload.FileUploadBase;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 统一异常处理类
 */
@ControllerAdvice
public class BaseExceptionHandler {

    /*@ExceptionHandler(value = Exception.class)
    @ResponseBody
    public MyResult error(Exception e){
        e.printStackTrace();
        return new MyResult(1, "执行出错");
    }*/

    @ExceptionHandler(value = MyException.class)
    @ResponseBody
    public MyResult error(MyException e){
        e.printStackTrace();
        return MyResult.build(e.getCode(),e.getMsg());
    }

    @ExceptionHandler(value = FileUploadBase.FileSizeLimitExceededException.class)
    @ResponseBody
    public MyResult error(Exception e){
        e.printStackTrace();
        return new MyResult(StatusCode.ERROR, "文件大小超出限制");
    }
}
